package cz.muni.fi.pa165.musiclibrary.musiclibraryweb.pages.search.result;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import cz.muni.fi.pa165.musiclibrary.api.service.dto.IArtistDTO;
import cz.muni.fi.pa165.musiclibrary.musiclibraryweb.pages.artist.ArtistPage;

/**
 *
 * @author Maros Kucbel
 * @date 2012-11-24T17:08:15+0100
 */
public final class ArtistsPanel extends Panel {

    private List<IArtistDTO> artists;
    
    public ArtistsPanel(String id, List<IArtistDTO> artists) {
        super(id);
        this.artists = artists;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();
        this.initComponents();
    }
    
    private void initComponents() {
        ListView<IArtistDTO> artistsView = new ListView<IArtistDTO>(ComponentIDs.ARTISTS_VIEW, this.artists) {

            @Override
            protected void populateItem(ListItem<IArtistDTO> item) {
                IArtistDTO artist = item.getModelObject();
                
                PageParameters params = new PageParameters();
                params.add("id", artist.getIdArtist().toString());
                Link<Void> artistLink = new BookmarkablePageLink<Void>(ComponentIDs.ARTIST_LINK, ArtistPage.class, params);
                artistLink.add(new Label(ComponentIDs.ARTIST_LINK_NAME, artist.getName()));
                item.add(artistLink);
            }
        };
        this.add(artistsView);
    }
    
    /** Identifiers of added components. */
    private static final class ComponentIDs {
        /** View of songs. */
        private static final String ARTISTS_VIEW = "artistsView";
        /** Link to song detail page. */
        private static final String ARTIST_LINK = "artistLink";
        /** Name of the song. */
        private static final String ARTIST_LINK_NAME = "artistLinkName";
    }
}